<!--
  停车场表添加页面
  User: YanZengBao
  Date: 2020-02-19
-->
<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">

<!-- BEGIN FORM-->
<div class="portlet light">
    <div class="portlet-title">
        <div class="caption">
            <span class="caption-subject font-red-sunglo bold uppercase">停车场表添加</span>
            <span class="caption-helper">添加一条停车场表数据</span>
        </div>
    </div>
    <div class="portlet-body form">
        <!-- BEGIN FORM-->
        <form action="#" class="form-horizontal" id="save-module">
            <div class="form-body">

                <!--  字段信息-->
                <!-- 编号(不允许重复) 字段信息-->
                <div class="form-group">
                    <label class="col-md-3 control-label">停车场编号</label>
                    <div class="col-md-7">
                        <div class="input-inline ">
                            <div class="input-group">
                                        <span class="input-group-addon">
                                            <i class="fa fa-edit"></i>
                                        </span>
                                <input type="text" class="form-control" maxlength="32" required name="number"
                                       placeholder="编号(不允许重复)">
                            </div>
                        </div>
                    </div>
                </div>
                <!-- 停车场名称 字段信息-->
                <div class="form-group">
                    <label class="col-md-3 control-label">停车场名称</label>
                    <div class="col-md-7">
                        <div class="input-inline ">
                            <div class="input-group">
                                        <span class="input-group-addon">
                                            <i class="fa fa-edit"></i>
                                        </span>
                                <input type="text" class="form-control" maxlength="100" required name="name"
                                       placeholder="停车场名称">
                            </div>
                        </div>
                    </div>
                </div>
                <!-- 停车场类型（0-封闭停车场 1-。。。） 字段信息-->
                <div class="form-group hide">
                    <label class="col-md-3 control-label">停车场类型</label>
                    <div class="col-md-7">
                        <div class="input-inline ">
                            <div class="input-group">
                                        <span class="input-group-addon">
                                            <i class="fa fa-edit"></i>
                                        </span>
                                <input type="number" class="form-control" required digits="true" name="parkType"
                                       value="0" placeholder="停车场类型（0-封闭停车场 1-。。。）">
                            </div>
                        </div>
                    </div>
                </div>

                <!-- 省 字段信息-->
                <div class="form-group ">
                    <label class="col-md-3 control-label">省份</label>
                    <div class="col-md-7">
                        <div class="input-inline ">
                            <div class="input-group">
                                        <span class="input-group-addon">
                                            <i class="fa fa-edit"></i>
                                        </span>
                                <select id="province" class="form-control" required name="province" onclick="chooseProvince()">
                                    <option>请选择省份</option>
                                    <option th:each="data,iterStat : ${cityList}" th:value="${data.id}"
                                            th:text="${data.name}"></option>
                                </select>
                            </div>
                        </div>
                    </div>
                </div>
                <!-- 市 字段信息-->
                <div class="form-group ">
                    <label class="col-md-3 control-label">市区</label>
                    <div class="col-md-7">
                        <div class="input-inline ">
                            <div class="input-group">
                                        <span class="input-group-addon">
                                            <i class="fa fa-edit"></i>
                                        </span>
                                <select id="city" class="form-control" required name="city" onclick="chooseCity()">

                                </select>
                            </div>
                        </div>
                    </div>
                </div>
                <!-- 区县 字段信息-->
                <div class="form-group ">
                    <label class="col-md-3 control-label">区/县</label>
                    <div class="col-md-7">
                        <div class="input-inline ">
                            <div class="input-group">
                                        <span class="input-group-addon">
                                            <i class="fa fa-edit"></i>
                                        </span>
                                <select id="county" class="form-control" required name="county"></select>
                            </div>
                        </div>
                    </div>
                </div>

                <!-- 详细地址 字段信息-->
                <div class="form-group">
                    <label class="col-md-3 control-label">详细地址</label>
                    <div class="col-md-7">
                        <div class="input-inline ">
                            <div class="input-group">
                                        <span class="input-group-addon">
                                            <i class="fa fa-edit"></i>
                                        </span>
                                <input type="text" class="form-control" maxlength="255" required name="address" placeholder="详细地址"> <!--style="width: 60%"-->
                                <!--<button type="button" class="form-control btn btn-info btn-sm" onclick="chooseAddress()" style="margin-left: 8px;width: 38%;">选择地址</button>-->
                            </div>
                        </div>
                    </div>
                </div>
                <!-- 是否对临时车开放(0:暂不开放 1:开放) 字段信息-->
                <div class="form-group">
                    <label class="col-md-3 control-label">是否对临时车开放</label>
                    <div class="col-md-7">
                        <div class="input-inline ">
                            <div class="input-group">
                                        <span class="input-group-addon">
                                            <i class="fa fa-edit"></i>
                                        </span>
                                <select class="form-control"required name="openStatus">
                                    <option value="0">封闭</option>
                                    <option value="1">开放</option>
                                </select>
                            </div>
                        </div>
                    </div>
                </div>
                <!-- 是否收费（0：不收费 1:收费） 字段信息-->
                <div class="form-group">
                    <label class="col-md-3 control-label">是否收费</label>
                    <div class="col-md-7">
                        <div class="input-inline ">
                            <div class="input-group">
                                        <span class="input-group-addon">
                                            <i class="fa fa-edit"></i>
                                        </span>
                                <select class="form-control"required name="feeStatus">
                                    <option value="0">免费</option>
                                    <option value="1">收费</option>
                                </select>
                            </div>
                        </div>
                    </div>
                </div>
                <!-- 是否允许超位入场（0-允许 1-禁止） 字段信息-->
                <div class="form-group">
                    <label class="col-md-3 control-label">是否允许超位入场</label>
                    <div class="col-md-7">
                        <div class="input-inline ">
                            <div class="input-group">
                                        <span class="input-group-addon">
                                            <i class="fa fa-edit"></i>
                                        </span>
                                <select class="form-control"required name="overParkinglotStatus">
                                    <option value="0">允许</option>
                                    <option value="1">禁止</option>
                                </select>
                            </div>
                        </div>
                    </div>
                </div>
                <!-- 停车场图片 字段信息-->
                <!--<div class="form-group">
                    <label class="col-md-3 control-label">停车场图片</label>
                    <div class="col-md-7">
                        <div class="input-inline ">
                            <div class="input-group">
                                        <span class="input-group-addon">
                                            <i class="fa fa-edit"></i>
                                        </span>
                                <input type="text" class="form-control" required name="imgUrl" placeholder="停车场图片">
                            </div>
                        </div>
                    </div>
                </div>-->
                <!-- 车位总数 字段信息-->
                <div class="form-group">
                    <label class="col-md-3 control-label">车位总数</label>
                    <div class="col-md-7">
                        <div class="input-inline ">
                            <div class="input-group">
                                        <span class="input-group-addon">
                                            <i class="fa fa-edit"></i>
                                        </span>
                                <input type="number" class="form-control" maxlength="5" required digits="true" name="parkinglotTotal"
                                       placeholder="车位总数">
                            </div>
                        </div>
                    </div>
                </div>
                <!-- 开放时间起 字段信息-->
                <div class="form-group">
                    <label class="col-md-3 control-label">开放时间起</label>
                    <div class="col-md-7">
                        <div class="input-inline ">
                            <div class="input-group">
                                        <span class="input-group-addon">
                                            <i class="fa fa-edit"></i>
                                        </span>
                                <input type="text" class="form-control datetimePicker" maxlength="20" required name="openStartTime"
                                       placeholder="开放时间起">
                            </div>
                        </div>
                    </div>
                </div>
                <!-- 开放时间止 字段信息-->
                <div class="form-group">
                    <label class="col-md-3 control-label">开放时间止</label>
                    <div class="col-md-7">
                        <div class="input-inline ">
                            <div class="input-group">
                                        <span class="input-group-addon">
                                            <i class="fa fa-edit"></i>
                                        </span>
                                <input type="text" class="form-control datetimePicker" maxlength="20" required name="openStopTime"
                                       placeholder="开放时间止">
                            </div>
                        </div>
                    </div>
                </div>
                <!-- 备注 字段信息-->
                <div class="form-group">
                    <label class="col-md-3 control-label">备注</label>
                    <div class="col-md-7">
                        <div class="input-inline ">
                            <div class="input-group">
                                        <span class="input-group-addon">
                                            <i class="fa fa-edit"></i>
                                        </span>
                                <input type="text" class="form-control" maxlength="255" name="intro" placeholder="备注">
                            </div>
                        </div>
                    </div>
                </div>

            </div>
            <div class="form-actions">
                <div class="row">
                    <div class="col-md-12">
                        <div class="row">
                            <div class="col-md-offset-3 col-md-7">
                                <button type="button" class="btn green" onclick="save();">保存</button>
                                <button type="button" class="btn default" onclick="layer.close(layer_addModule);">取消
                                </button>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </form>
        <!-- END FORM-->
    </div>
</div>

<script>

    $(function () {
        //初始化页面
        initPage();
    });


    $(".datetimePicker").datetimepicker({
        format: 'hh:ii:00',
        language:"zh-CN",
        startView: 1,
        minView: 0,
        forceParse: true,
        minuteStep: 10,
        autoclose: true,
    });

    //根据省ID选择市
    function chooseProvince() {
        $("#city").empty();
        $("#county").empty();
        var options = $("#province option:selected");
        if (options.text().trim() != "请选择省份" && "" != options.text().trim()) {
            tools.post("/city/findCityByParentId", {"parentId": options.val()}, function (data) {
                $("#city").append('<option value="">请选择市区</option>');
                for (let cs in data.data) {
                    $("#city").append("<option value=\"" + data.data[cs].id + "\">" + data.data[cs].name + "</option>");
                }
                ;
            });
        }
    }

    //根据市ID选择区/县
    function chooseCity() {
        $("#county").empty();
        var options = $("#city option:selected");
        if (options.text() != "请选择市区" && "" != options.text().trim()) {
            tools.post("/city/findCountyByParentId", {"parentId": options.val()}, function (data) {
                $("#county").append('<option value="">请选择区/县</option>');
                for (let cs in data.data) {
                    $("#county").append('<option value="' + data.data[cs].id + '">' + data.data[cs].name + '</option>')
                }
                ;
            });
        }
    }


    /**
     * todo
     * 打开百度地图选择详细地址
     */
    function chooseAddress() {
        var cityName=$("#city option:selected").text().trim();
        console.log(cityName);
        if(cityName ==null || cityName == '' || cityName == '请选择市区'){
            layer.msg("请选择停车场所在的城市",{icon:0,time:1000});
            return;
        }else{
            $.post("/park/chooseAddress", {"cityName":cityName}, function(html){
                window.layer_addModule = layer.open({
                    id:"addressModule",
                    type: 1,
                    title:"选择停车场的详细地址",
                    area:['900px','600px'],
                    btn:['关闭','取消'],
                    content: html,
                    anim:1,
                    shadeClose:false,
                    cancel: function(){}
                });
            });
        }
    }


    function save() {
        let param = tools.formParams("save-module");
        if (tools.valid("save-module")) {
            tools.post("/park/save", param, function (data) {
                if (data.success) {
                    layer.msg(data.message, {icon: 1, time: 2000}, function () {
                        //刷新列表页面
                        toPage(null);
                        //关闭弹窗
                        layer.close(layer_addModule);
                    });
                } else {
                    tools.errorTip(data.code,data.message);
                }
            });
        }
    }

</script>
</html>